package com.jrh.web.user.devtool;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jrh.domain.user.LoginUserInfo;
import com.jrh.web.member.tools.UserAuthUtil;

/**
 * 开发期渲染VM工具类
 * 
 * @author jasen.hsu.cn@gmail.com 2012-7-21 下午9:26:09
 */
@Controller
@RequestMapping("/dev")
public class DevToolController {

    @RequestMapping("/test")
    public String test(HttpServletRequest request) {
        String vm = request.getParameter("vm");
        return vm.replaceAll("_", "/");
    }

    @RequestMapping(method = RequestMethod.GET, value = "/login/{id}/{type}")
    public String userLogin(@PathVariable("id") String id, @PathVariable("type") String type,
                            HttpServletRequest request, HttpServletResponse response, Model model) {

        LoginUserInfo loginUserInfo = new LoginUserInfo();
        loginUserInfo.setId(Long.valueOf(id));
        loginUserInfo.setLoginId("test");
        if (LoginUserInfo.USER_TYPE_SELLER.equals(type)) {
            loginUserInfo.setNickname("测试卖家");
            loginUserInfo.setType(type);
        } else {
            loginUserInfo.setNickname("测试买家");
            loginUserInfo.setType("0");
        }
        loginUserInfo.setSite("jrh");
        UserAuthUtil.signIn(loginUserInfo, request, response);
        model.addAttribute("user", UserAuthUtil.getUserInfo(request, response));
        return "ok";
    }
}
